/*
 * @lc app=leetcode.cn id=69 lang=cpp
 *
 * [69] Sqrt(x)
 */

// @lc code=start
class Solution {
public:
    int mySqrt(int x) {
        int left = 0;
        int right = x;

        while (left <= right) {
            int mid = (left + right) / 2;
            if ((long long)mid * mid > x) {
                right = mid - 1; 
            } else {
                left = mid + 1;
            }
        }

        return right;
    }
};
// @lc code=end

